<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="javascript">
    var op1 = function (a,b){
        return a+b;
    }
    var op2 = function (a,b){
        return a-b;
    }
    var op3 = function (a,b){
        return a*b;
    }
    var op4 = function (a,b){
        return a/b;
    }
    //回调函数
    function op(a,b,fn){
        var res=fn(a,b);
        var resEle=document.getElementById("res");
        resEle.innerText=res;
    }
    function clk(){
        var inputs=document.querySelectorAll("input");
        var a = inputs[0].value;
        var b = inputs[0].value;
        var select = document.querySelector("select");
        var index = select.selectedIndex;
        index++;
        var fname = "op"+index;
        eval("var fn =" + fname +";");
        a=parseInt(a);
        b=parseInt(b);
        op(a,b,fn);
    }
</script>
<body>
<h2>JS回调</h2>
<input type="text">
<select>
    <option >+</option>
    <option >-</option>
    <option >*</option>
    <option >/</option>
</select>
<input type="text">
<button onclick="clk();">=</button>
<span id="res"></span>

</body>
</html>